package pri.jz.keeper.ui.content

import android.content.Intent
import android.os.Handler
import androidx.activity.viewModels
import androidx.compose.runtime.Composable
import pri.jz.keeper.ui.content.personal.userinfo.UserInfoActivity
import pri.jz.keeper.ui.base.BaseActivity
import pri.jz.keeper.ui.base.BaseViewModel
import pri.jz.keeper.ui.content.personal.setting.SettingActivity
import pri.jz.keeper.ui.uistate.ContentState

/**
 *Author by: JZ
 *Email: 2451756617@qq.com
 *PS:
 */
class ContentActivity : BaseActivity() {
    private val viewModel: ContentViewModel by viewModels()
    override fun initData() {
        super.initData()
        fullScreen(true)
        val id = intent.getIntExtra("userId",-1)
        if (id != -1) {
            viewModel.initLoading(id)
        }
    }
    @Composable
    override fun OnCreateView() {
        ContentView()
    }

    override suspend fun onObserver() {
        viewModel.state.collect { state ->
            when (state) {
                is ContentState.UserInfo -> onUserInfo()
                is ContentState.Setting -> onSetting()
                is ContentState.Default -> {}
            }
        }
    }

    override fun getViewModel(): BaseViewModel {
        return viewModel
    }

    private fun onUserInfo() {
        startActivity(Intent(this@ContentActivity, UserInfoActivity::class.java))
    }

    private fun onSetting() {
        startActivity(Intent(this@ContentActivity, SettingActivity::class.java))
    }

    override fun onDestroy() {
        super.onDestroy()
    }



}